
package com.craterhill.java.ems.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.craterhill.java.ems.common.beans.Position;
import com.craterhill.java.ems.common.beans.Section;
import com.craterhill.java.ems.dao.impl.AbstractDao;
import com.craterhill.java.ems.dao.utils.EMSResultSetExtractor;

public interface SectionDao extends EMSDao<Position> {

	public final String FIELD_LIST = "obj.section_id, obj.class_id, obj.section_name, obj.staff_id" + AbstractDao.MONITER_FIELDS;

	public final String FIND_SECTIONS_BY_CLASS = "select " + FIELD_LIST + " from sections obj where obj.class_id = ?";

	public final String SAVE_SECTIONS = "insert into sections (class_id, section_name, staff_id, created_by) values (?, ?, ?, ?)";
	public final String DELETE_SECTIONS = "delete from sections where class_id = ?";

	public List<Section> findByClasses(final int classId);

	public boolean save(final int classId, final List<Section> sections);

	public final class SectionExtractor extends EMSResultSetExtractor<Section> {

		@Override
		protected Section extractResultSetData(ResultSet resultSet) throws SQLException {
			Section section = new Section();
			section.setSectionId(resultSet.getInt(1));
			section.setSectionId(resultSet.getInt(2));
			section.setSectionName(resultSet.getString(3));
			section.setTeacherId(resultSet.getInt(4));

			section.setStatus(resultSet.getBoolean(5));
			section.setCreatedBy(resultSet.getInt(6));
			section.setCreatedDate(resultSet.getDate(7));
			section.setModifiedDate(resultSet.getDate(8));
			return section;
		}
	}
}
